package com.xmhmyh.generalframework.project.sys.conversion;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmhmyh.generalframework.project.sys.entity.Menu;
import com.xmhmyh.generalframework.project.sys.entity.User;
import com.xmhmyh.generalframework.project.sys.vo.MenuBtnVO;
import com.xmhmyh.generalframework.project.sys.vo.UserVO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


public class User2UserVOConversion {

    public static UserVO conversion(User user) {
        UserVO userVO = new UserVO();
        userVO.setId(user.getId());
        userVO.setUserName(user.getUserName());
        userVO.setName(user.getName());
        userVO.setPhone(user.getPhone());
        userVO.setSex(user.getSex());
        userVO.setStatus(user.getStatus());
        userVO.setRemark(user.getRemark());
        userVO.setIsAdmin(user.getIsAdmin());
        return userVO;
    }

    public static List<UserVO> conversionList(List<User> userList) {
        List<UserVO> userVOList = userList.stream().map(user -> {
            return conversion(user);
        }).collect(Collectors.toList());
        return userVOList;
    }

    public static IPage<UserVO> pageConversion(IPage<User> user) {
        IPage<UserVO> page = new Page<>();
        page.setPages(user.getPages());
        page.setCurrent(user.getCurrent());
        page.setTotal(user.getTotal());
        page.setSize(user.getSize());
        List<UserVO> userVOList = conversionList(user.getRecords());
        page.setRecords(userVOList);
        return page;
    }
}
